package com.wnhz.work.yz.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.fragment.record.AccurateFragment;
import com.wnhz.work.yz.fragment.record.CluesFragment;

import java.util.ArrayList;
import java.util.List;

public class OtherRecodeActivity extends BaseActivity implements View.OnClickListener {


    private List<Fragment> fragmentList;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;

    private CluesFragment fragment1;
    private AccurateFragment fragment2;
    private TextView title1, title2;
    private View line1, line2;
    private int textColorNor, textColorCli;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_records);
        initData();
        initTitle();
        initView();
    }

    private String user_id;

    private void initData() {
        user_id = getIntent().getStringExtra("user_id");
    }

    private void initView() {

        title1 = (TextView) findViewById(R.id.shop_title1);
        title2 = (TextView) findViewById(R.id.shop_title2);
        line1 = findViewById(R.id.line1);
        line2 = findViewById(R.id.line2);
        findViewById(R.id.shop_title1).setOnClickListener(this);
        findViewById(R.id.shop_title2).setOnClickListener(this);


        fragmentList = new ArrayList<>();
        fragment1 = new CluesFragment();
        fragment2 = new AccurateFragment();
        fragmentList.add(fragment1);
        fragmentList.add(fragment2);

        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fl_shopping_card2, fragment1);
        transaction.add(R.id.fl_shopping_card2, fragment2);

        transaction.hide(fragment2);
        transaction.commit();

    }

    private void initTitle() {
        textColorNor = getResources().getColor(R.color.text_two);
        textColorCli = getResources().getColor(R.color.main_color);

        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("客户信息");
        findViewById(R.id.search_tv).setOnClickListener(this);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.shop_title1:
                if (MyApplication.getInstance().getUserBean() != null) {
                    hideFragment(0);
                    title1.setTextColor(textColorCli);
                    title2.setTextColor(textColorNor);
                    line1.setVisibility(View.VISIBLE);
                    line2.setVisibility(View.INVISIBLE);
                }
                break;
            case R.id.shop_title2:
                if (MyApplication.getInstance().getUserBean() != null) {
                    hideFragment(1);
                    title1.setTextColor(textColorNor);
                    title2.setTextColor(textColorCli);
                    line1.setVisibility(View.INVISIBLE);
                    line2.setVisibility(View.VISIBLE);
                }
                break;

        }

    }

    private void hideFragment(int index) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        for (int i = 0; i < fragmentList.size(); i++) {
            if (i == index) {
                transaction.show(fragmentList.get(i));
            } else {
                transaction.hide(fragmentList.get(i));
            }
        }
        transaction.commit();
    }


}
